<?php
/* 	These code was generated using phpCIGen v 2.a (21/05/2012)
	#zaqi 		zaqi.smart@gmail.com,http://zenzaqi.blogspot.com, 
	#CV. Trust Solution, jl. Saronojiwo 2/19 Surabaya, http://www.ts.co.id
	
	+ Module  		: t_project Controller
	+ Description	: For record controller process back-end
	+ Filename 		: C_t_project.php
 	+ creator 		: 
 	+ Created on 24/Jul/2012 10:52:52
	
*/

//class of t_project
class C_t_project extends CI_Controller {

	//constructor
	function __construct(){
		parent::__construct();
		
		$this->load->model('m_t_project', '', TRUE);
		checkLogin();
	}
	
	//set index
	function index(){
		$info = $this->m_public_function->get_info();
		$data['project_companyNameField'] = $info->info_nama;
		$this->load->view('main/v_t_project',$data);
	}
	
	//event handler action
	function get_action(){
		$task = $_POST['task'];
		switch($task){
			case "LIST":
				$this->t_project_list();
				break;
			case "UPDATE":
				$this->t_project_update();
				break;
			case "CREATE":
				$this->t_project_create();
				break;
			case "DELETE":
				$this->t_project_delete();
				break;
			case "SEARCH":
				$this->t_project_search();
				break;
			case "PRINT":
				$this->t_project_print();
				break;
			case "EXCEL":
				$this->t_project_export_excel();
				break;
			default:
				echo "{failure:true}";
				break;
		}
	}
	
	//function fot list record
	function t_project_list(){
		
		$query = isset($_POST['query']) ? @$_POST['query'] : "";
		$start = (integer) (isset($_POST['start']) ? @$_POST['start'] : @$_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? @$_POST['limit'] : @$_GET['limit']);
		$result=$this->m_t_project->t_project_list($query,$start,$end);
		echo $result;
	}
	
	//function for create new record
	function t_project_create(){
		//POST varible here
		//auto increment, don't accept anything from form values
		$m_branch=@$_POST["m_branch"];
		$m_branch=is_numeric($m_branch)?$m_branch:0;
		$project_type=trim(@$_POST["project_type"]);
		$project_type=htmlentities($project_type,ENT_QUOTES);
		$project_code=trim(@$_POST["project_code"]);
		$project_code=htmlentities($project_code,ENT_QUOTES);
		$project_name=trim(@$_POST["project_name"]);
		$project_name=htmlentities($project_name,ENT_QUOTES);
		$project_shortname=trim(@$_POST["project_shortname"]);
		$project_shortname=htmlentities($project_shortname,ENT_QUOTES);
		$project_pm=trim(@$_POST["project_pm"]);
		$project_pm=htmlentities($project_pm,ENT_QUOTES);
		$project_semcm=trim(@$_POST["project_semcm"]);
		$project_semcm=htmlentities($project_semcm,ENT_QUOTES);
		$project_value=@$_POST["project_value"];
		$project_value=is_numeric($project_value)?$project_value:0;
		$project_value_minusppn=@$_POST["project_value_minusppn"];
		$project_value_minusppn=is_numeric($project_value_minusppn)?$project_value_minusppn:0;
		$project_start=trim(@$_POST["project_start"]);
		$project_start=date('Y-m-d', strtotime($project_start));
		$project_p1=trim(@$_POST["project_p1"]);
		$project_p1=date('Y-m-d', strtotime($project_p1));
		$project_p2=trim(@$_POST["project_p2"]);
		$project_p2=date('Y-m-d', strtotime($project_p2));
		$project_div=@$_POST["project_div"];
		$project_div=is_numeric($project_div)?$project_div:0;
		$project_created_date=date(LONG_FORMATDATE);
		$project_created_by=$_SESSION[SESSION_USERID];
		
		
		$result=$this->m_t_project->t_project_create($m_branch, $project_type, $project_code, $project_name, $project_shortname, $project_pm, $project_semcm,
				$project_value, $project_value_minusppn, $project_start, $project_p1, $project_p2, $project_div, $project_created_date, $project_created_by);
		echo $result;
	}
	
	
	//function for update record
	function t_project_update(){
		//POST variable here
		$m_branch=@$_POST["m_branch"];
		$m_branch=is_numeric($m_branch)?$m_branch:0;
		$project_id=@$_POST["project_id"];
		$project_id=is_numeric($project_id)?$project_id:0;
		$project_flag=trim(@$_POST["project_flag"]);
		$project_flag=htmlentities($project_flag,ENT_QUOTES);
		$project_code=trim(@$_POST["project_code"]);
		$project_code=htmlentities($project_code,ENT_QUOTES);
		$project_type=trim(@$_POST["project_type"]);
		$project_type=htmlentities($project_type,ENT_QUOTES);
		$project_name=trim(@$_POST["project_name"]);
		$project_name=htmlentities($project_name,ENT_QUOTES);
		$project_shortname=trim(@$_POST["project_shortname"]);
		$project_shortname=htmlentities($project_shortname,ENT_QUOTES);
		$project_pm=trim(@$_POST["project_pm"]);
		$project_pm=htmlentities($project_pm,ENT_QUOTES);
		$project_semcm=trim(@$_POST["project_semcm"]);
		$project_semcm=htmlentities($project_semcm,ENT_QUOTES);
		$project_value=trim(@$_POST["project_value"]);
		$project_start=trim(@$_POST["project_start"]);
		$project_p1=trim(@$_POST["project_p1"]);
		$project_p2=trim(@$_POST["project_p2"]);
		$project_div=@$_POST["project_div"];
		$project_div=is_numeric($project_div)?$project_div:0;
		$project_updated_date=date(LONG_FORMATDATE);
		$project_updated_by=$_SESSION[SESSION_USERID];
		
		$result = $this->m_t_project->t_project_update($m_branch,$project_id,$project_flag,$project_code,$project_type,$project_name,$project_shortname,$project_pm,$project_semcm,
				$project_value,$project_start,$project_p1,$project_p2,$project_div,
				$project_updated_date,$project_updated_by);
		echo $result;
	}
	
	//function for delete selected record
	function t_project_delete(){
		$ids = @$_POST['ids']; // Get our array back and translate it :
		$pkid = json_decode(stripslashes($ids));
		$result=$this->m_t_project->t_project_delete($pkid);
		echo $result;
	}

	//function for advanced search
	function t_project_search(){
		//POST varibale here
		$project_id=@$_POST["project_id"];
		$project_id=is_numeric($project_id)?$project_id:0;
		$project_flag=trim(@$_POST["project_flag"]);
		$project_flag=htmlentities($project_flag,ENT_QUOTES);
		$project_code=trim(@$_POST["project_code"]);
		$project_code=htmlentities($project_code,ENT_QUOTES);
		$project_type=trim(@$_POST["project_type"]);
		$project_type=htmlentities($project_type,ENT_QUOTES);
		$project_name=trim(@$_POST["project_name"]);
		$project_name=htmlentities($project_name,ENT_QUOTES);
		$project_shortname=trim(@$_POST["project_shortname"]);
		$project_shortname=htmlentities($project_shortname,ENT_QUOTES);
		$project_pm=trim(@$_POST["project_pm"]);
		$project_pm=htmlentities($project_pm,ENT_QUOTES);
		$project_semcm=trim(@$_POST["project_semcm"]);
		$project_semcm=htmlentities($project_semcm,ENT_QUOTES);
		$project_value=trim(@$_POST["project_value"]);
		$project_start=trim(@$_POST["project_start"]);
		$project_p1=trim(@$_POST["project_p1"]);
		$project_p2=trim(@$_POST["project_p2"]);
		$project_created_date=trim(@$_POST["project_created_date"]);
		$project_created_by=trim(@$_POST["project_created_by"]);
		$project_created_by=htmlentities($project_created_by,ENT_QUOTES);
		$project_updated_date=trim(@$_POST["project_updated_date"]);
		$project_updated_by=trim(@$_POST["project_updated_by"]);
		$project_updated_by=htmlentities($project_updated_by,ENT_QUOTES);
		$project_updated_count=@$_POST["project_updated_count"];
		$project_updated_count=is_numeric($project_updated_count)?$project_updated_count:0;
		$m_branch=@$_POST["m_branch_id"];
		$m_branch=is_numeric($m_branch)?$m_branch:0;
		
		$start = (integer) (isset($_POST['start']) ? $_POST['start'] : $_GET['start']);
		$end = (integer) (isset($_POST['limit']) ? $_POST['limit'] : $_GET['limit']);
		$result = $this->m_t_project->t_project_search($project_id ,$project_flag ,$project_code ,$project_type ,$project_name ,$project_shortname ,$project_pm ,$project_semcm ,$project_value ,$project_start ,$project_p1 ,$project_p2 ,$project_created_date ,$project_created_by ,$project_updated_date ,$project_updated_by ,$project_updated_count ,$m_branch ,$start,$end);
		echo $result;
	}


	function t_project_print(){
  		//POST varibale here
		$project_id=@$_POST["project_id"];
		$project_id=is_numeric($project_id)?$project_id:0;
		$project_flag=trim(@$_POST["project_flag"]);
		$project_flag=htmlentities($project_flag,ENT_QUOTES);
		$project_code=trim(@$_POST["project_code"]);
		$project_code=htmlentities($project_code,ENT_QUOTES);
		$project_type=trim(@$_POST["project_type"]);
		$project_type=htmlentities($project_type,ENT_QUOTES);
		$project_name=trim(@$_POST["project_name"]);
		$project_name=htmlentities($project_name,ENT_QUOTES);
		$project_shortname=trim(@$_POST["project_shortname"]);
		$project_shortname=htmlentities($project_shortname,ENT_QUOTES);
		$project_pm=trim(@$_POST["project_pm"]);
		$project_pm=htmlentities($project_pm,ENT_QUOTES);
		$project_semcm=trim(@$_POST["project_semcm"]);
		$project_semcm=htmlentities($project_semcm,ENT_QUOTES);
		$project_value=trim(@$_POST["project_value"]);
		$project_start=trim(@$_POST["project_start"]);
		$project_p1=trim(@$_POST["project_p1"]);
		$project_p2=trim(@$_POST["project_p2"]);
		$project_created_date=trim(@$_POST["project_created_date"]);
		$project_created_by=trim(@$_POST["project_created_by"]);
		$project_created_by=htmlentities($project_created_by,ENT_QUOTES);
		$project_updated_date=trim(@$_POST["project_updated_date"]);
		$project_updated_by=trim(@$_POST["project_updated_by"]);
		$project_updated_by=htmlentities($project_updated_by,ENT_QUOTES);
		$project_updated_count=@$_POST["project_updated_count"];
		$project_updated_count=is_numeric($project_updated_count)?$project_updated_count:0;
		$m_branch=@$_POST["m_branch_id"];
		$m_branch=is_numeric($m_branch)?$m_branch:0;
		$option=$_POST['currentlisting'];
		$filter=$_POST["query"];
		
		$data["data_print"] = $this->m_t_project->t_project_print($project_id ,$project_flag ,$project_code ,$project_type ,$project_name ,$project_shortname ,$project_pm ,$project_semcm ,$project_value ,$project_start ,$project_p1 ,$project_p2 ,$project_created_date ,$project_created_by ,$project_updated_date ,$project_updated_by ,$project_updated_count ,$m_branch ,$option,$filter);
		$print_view=$this->load->view("main/p_t_project.php",$data,TRUE);
		if(!file_exists("print")){
			mkdir("print");
		}
		$print_file=fopen("print/t_project_printlist.html","w+");
		fwrite($print_file, $print_view);
		echo '1';        
	}
	/* End Of Function */

	/* Function to Export Excel document */
	function t_project_export_excel(){
		//POST varibale here
		$project_id=@$_POST["project_id"];
		$project_id=is_numeric($project_id)?$project_id:0;
		$project_flag=trim(@$_POST["project_flag"]);
		$project_flag=htmlentities($project_flag,ENT_QUOTES);
		$project_code=trim(@$_POST["project_code"]);
		$project_code=htmlentities($project_code,ENT_QUOTES);
		$project_type=trim(@$_POST["project_type"]);
		$project_type=htmlentities($project_type,ENT_QUOTES);
		$project_name=trim(@$_POST["project_name"]);
		$project_name=htmlentities($project_name,ENT_QUOTES);
		$project_shortname=trim(@$_POST["project_shortname"]);
		$project_shortname=htmlentities($project_shortname,ENT_QUOTES);
		$project_pm=trim(@$_POST["project_pm"]);
		$project_pm=htmlentities($project_pm,ENT_QUOTES);
		$project_semcm=trim(@$_POST["project_semcm"]);
		$project_semcm=htmlentities($project_semcm,ENT_QUOTES);
		$project_value=trim(@$_POST["project_value"]);
		$project_start=trim(@$_POST["project_start"]);
		$project_p1=trim(@$_POST["project_p1"]);
		$project_p2=trim(@$_POST["project_p2"]);
		$project_created_date=trim(@$_POST["project_created_date"]);
		$project_created_by=trim(@$_POST["project_created_by"]);
		$project_created_by=htmlentities($project_created_by,ENT_QUOTES);
		$project_updated_date=trim(@$_POST["project_updated_date"]);
		$project_updated_by=trim(@$_POST["project_updated_by"]);
		$project_updated_by=htmlentities($project_updated_by,ENT_QUOTES);
		$project_updated_count=@$_POST["project_updated_count"];
		$project_updated_count=is_numeric($project_updated_count)?$project_updated_count:0;
		$m_branch=@$_POST["m_branch_id"];
		$m_branch=is_numeric($m_branch)?$m_branch:0;
		$option=$_POST['currentlisting'];
		$filter=$_POST["query"];
		$data["type"]="excel";
		$data["data_print"] = $this->m_t_project->t_project_print($project_id ,$project_flag ,$project_code ,$project_type ,$project_name ,$project_shortname ,$project_pm ,$project_semcm ,$project_value ,$project_start ,$project_p1 ,$project_p2 ,$project_created_date ,$project_created_by ,$project_updated_date ,$project_updated_by ,$project_updated_count ,$m_branch ,$option,$filter);
		$print_view=$this->load->view("main/p_t_project.php",$data,TRUE);
		if(!file_exists("print")){
			mkdir("print");
		}
		$print_file=fopen("print/t_project_printlist.xls","w+");
		fwrite($print_file, $print_view);
		echo '1';   
			
	}
	
	// Encodes a SQL array into a JSON formated string
	function JEncode($arr){
		if (version_compare(PHP_VERSION,"5.2","<"))
		{    
			require_once("./JSON.php"); //if php<5.2 need JSON class
			$json = new Services_JSON();//instantiate new json object
			$data=$json->encode($arr);  //encode the data in json format
		} else {
			$data = json_encode($arr);  //encode the data in json format
		}
		return $data;
	}
	
	// Decode a SQL array into a JSON formated string
	function JDecode($arr){
		if (version_compare(PHP_VERSION,"5.2","<"))
		{    
			require_once("./JSON.php"); //if php<5.2 need JSON class
			$json = new Services_JSON();//instantiate new json object
			$data=$json->decode($arr);  //decode the data in json format
		} else {
			$data = json_decode($arr);  //decode the data in json format
		}
		return $data;
	}
		
}
?>